package com.sunday.fangdaifu.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sunday.fangdaifu.R;
import com.sunday.fangdaifu.widgets.ShowBigImage;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/7/5.
 */

public class HistoryDetailImageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<String> dataSet;
    private View.OnClickListener onClickListener;


    public HistoryDetailImageAdapter(Context context) {
        mContext = context;

    }

    public void setData(List<String> datas) {
        dataSet = datas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_history_detail_img, parent, false);
        return new ItemViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final String historyTaskList = dataSet.get(position);
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        Picasso.with(mContext)
                .load(historyTaskList)
                .error(R.drawable.default_error)
                .resize(150, 150)
                .into(viewHolder.img);
    }

    @Override
    public int getItemCount() {
        return dataSet == null ? 0 : dataSet.size();
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        @Bind(R.id.img)
        ImageView img;

        public ItemViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            img.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(mContext, ShowBigImage.class);
            intent.putStringArrayListExtra("data", (ArrayList<String>) dataSet);
            mContext.startActivity(intent);
        }
    }

}
